package top.humbleyuan.designmode.subpub;

/**
 * @Author HumbleYuan
 * @Date 2019/12/18 20:17
 * @Des
 */
public class SubscriberImpl<T> implements ISubscriber<T> {
    private String name;

    public SubscriberImpl(String name) {
        this.name = name;
    }

    // 退订
    @Override
    public void unsub(SubPubPlatform subPubPlatform) {
        subPubPlatform.unSub(this);
    }

    // 订阅
    @Override
    public void sub(SubPubPlatform subPubPlatform) {
        subPubPlatform.sub(this);
    }

    @Override
    public void update(String publisher, T msg) {
        System.out.println(this.name + "收到了订阅信息：" + msg.toString());
    }
}
